package com.aclass.xqx.classscreen;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.aclass.xqx.classscreen.adapter.ClassAdapter;
import com.aclass.xqx.classscreen.adapter.NameAdapter;
import com.aclass.xqx.classscreen.db.AddData;
import com.aclass.xqx.classscreen.db.CardDao;
import com.aclass.xqx.classscreen.db.CardStudent;
import com.aclass.xqx.classscreen.db.Cardnumber;
import com.aclass.xqx.classscreen.db.ClassSchedule;
import com.aclass.xqx.classscreen.db.StudentNews;
import com.aclass.xqx.classscreen.db.StudentSign;
import com.aclass.xqx.classscreen.model.MainModel;
import com.aclass.xqx.classscreen.service.LocalService;
import com.aclass.xqx.classscreen.service.RemoteService;
import com.aclass.xqx.classscreen.ui.StudentPhotosActivity;
import com.aclass.xqx.classscreen.ui.VerticalText;
import com.aclass.xqx.classscreen.ui.VideoActivity;
import com.aclass.xqx.classscreen.utlis.AppUtlis;
import com.aclass.xqx.classscreen.utlis.AsyncTaskSoapUtil;
import com.aclass.xqx.classscreen.utlis.ClassCalendar;
import com.aclass.xqx.classscreen.utlis.Constant;
import com.aclass.xqx.classscreen.utlis.DialogUtlis;
import com.aclass.xqx.classscreen.utlis.LocationUtlis;
import com.aclass.xqx.classscreen.utlis.PrefUtild;
import com.aclass.xqx.classscreen.utlis.SystemManager;
import com.aclass.xqx.classscreen.view.HorseView;
import com.aclass.xqx.classscreen.view.ScrollTextView;
import com.sunfusheng.marqueeview.MarqueeView;
import com.zhouwei.mzbanner.MZBannerView;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import static android.R.id.list;

/**
 * 主页界面
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    RecyclerView main_recycler_view,main_recycler_name,main_recycler_name1;
    private TextView tv_day;
    private EditText tbCard;
    private ListView lv_debug;
    private LinearLayout ll_news,ll_schedule,ll_schedulea;
    private TextView tv_calssname,tv_weekDays,tv_classtime,tv_count,tv_to,tv_noto,tv_weather,tv_headmaster,tv_SchoolTitle,tv_labur;
    private ArrayAdapter arrayAdapter;
    private NewsReceiver newsReceiver;
    public static List<String> initialList=new ArrayList<>();
    private MZBannerView mNormalBanner;
    private MainModel mainModel;
    Timer timer;
    private HorseView tv_news;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        new Thread(run2).start();
        try {
            PrefUtild.INSTANCE.setString(this, Constant.NPACKAGE, AppUtlis.packageMas(this));
            PrefUtild.INSTANCE.setString(this, Constant.CODE, AppUtlis.packageCode(this)+"");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        String class_no = PrefUtild.INSTANCE.getString(getApplicationContext(), "class_no", "");
        if (!class_no.equals("")) {
            Intent intent = new Intent(this, LocalService.class);
            startService(intent);
            Intent intent1 = new Intent(this, RemoteService.class);
            startService(intent1);
        }
        Log.e("ATG",ClassCalendar.getCardtime());
        mainModel=new MainModel(this);

//        getNamePwd();
        // 动态注册广播
        newsReceiver = new NewsReceiver();
        registerReceiver(newsReceiver, filter());
        initView();
        initIdNumber();
        initData();
        getNamePwd();
        initList();
    }

    @Override
    public void onStart() {
        super.onStart();
//        text1_stv.startTextScroll();
        text1_stv.startFlipping();
        tv_SchoolContent.startFlipping();
    }

    @Override
    public void onStop() {
        super.onStop();
//        text1_stv.stopTextScroll();
        text1_stv.stopFlipping();
        tv_SchoolContent.stopFlipping();
    }

    MarqueeView text1_stv,tv_SchoolContent;
    //布局id
    public void initView(){
        tv_day= (TextView) findViewById(R.id.tv_day);
        tv_day.setText(ClassCalendar.getStringDay());
        ll_news= (LinearLayout) findViewById(R.id.ll_news);
        tv_headmaster= (TextView) findViewById(R.id.tv_headmaster);
        text1_stv = (MarqueeView) findViewById(R.id.marqueeView);
        ArtClass();
        text1_stv.startWithList(artCalss);

        tv_headmaster.setText("班主任: "+mainModel.classteachername());
        tv_headmaster.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String etherNetIP = AppUtlis.getEtherNetIP();
                Toast.makeText(MainActivity.this,etherNetIP,Toast.LENGTH_LONG).show();

            }
        });
        main_recycler_view= (RecyclerView) findViewById(R.id.main_recycler_view);
        main_recycler_name= (RecyclerView) findViewById(R.id.main_recycler_name);
        main_recycler_name1= (RecyclerView) findViewById(R.id.main_recycler_name1);
        tbCard= (EditText) findViewById(R.id.tbCard);
        ll_schedule= (LinearLayout) findViewById(R.id.ll_schedule);
        ll_schedulea= (LinearLayout) findViewById(R.id.ll_schedulea);
        Schedulemo();
        Scheduleafternoon();

        lv_debug= (ListView) findViewById(R.id.lv_debug);
        tv_calssname= (TextView) findViewById(R.id.tv_calssname);
        tv_calssname.setOnClickListener(this);
        tv_weekDays= (TextView) findViewById(R.id.tv_weekDays);
        tv_classtime= (TextView) findViewById(R.id.tv_classtime);
        tv_labur= (TextView) findViewById(R.id.tv_labur);
        tv_calssname.setText(mainModel.classname());
        tv_weather= (TextView) findViewById(R.id.tv_weather);
        tv_classtime.setText(ClassCalendar.getInttimes());
        tv_count= (TextView) findViewById(R.id.tv_count);
        tv_to= (TextView) findViewById(R.id.tv_to);
        tv_noto= (TextView) findViewById(R.id.tv_noto);
        tv_SchoolTitle= (TextView) findViewById(R.id.tv_SchoolTitle);
        tv_SchoolTitle.setText(mainModel.ArtSchool());
        tv_SchoolContent= (MarqueeView) findViewById(R.id.SchoolMarqueeView);
        ArtSchool();
        tv_SchoolContent.startWithList(ArtSchool);
//        tv_SchoolContent.setText(mainModel.ArtSchool(1));
        getTo();
        Labour();
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        tv_classtime.setText(ClassCalendar.getInttimes());
                        tbCard.requestFocus();
                    }
                });
//                View rootview = MainActivity.this.getWindow().getDecorView();
//                if (rootview.isFocusable()){
//                    int id = rootview.findFocus().getId();
//                    if (id!=tbCard.getId()){
//                        tbCard.requestFocus();
////                    Log.e("tag","不相同");
//                    }
//                }

//                else{
//                    Log.e("tag","相同");
//                }
            }
        },1000,15000);
        tv_classtime.setOnClickListener(this);
        tv_news= (HorseView) findViewById(R.id.tv_news);
        getNews();
        tv_weekDays.setText(ClassCalendar.getStringWeekDays());
    }
        NameAdapter StudyAdapter,ProgressAdapter;
        ClassAdapter adapter;
        List<String> honor=new ArrayList<>();
    public void initData(){
        try {
            mainModel.upPackages();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        LocationUtlis locationUtlis=new LocationUtlis(getApplicationContext());
        locationUtlis.Location();
        GridLayoutManager layoutManager1 = new GridLayoutManager(this, 3);
        GridLayoutManager layoutManager2 = new GridLayoutManager(this, 3);
        main_recycler_name.setLayoutManager(layoutManager2);
        main_recycler_name1.setLayoutManager(layoutManager1);
        StudyAdapter = new NameAdapter(this, Study);
        main_recycler_name1.setAdapter(StudyAdapter);
        ProgressAdapter = new NameAdapter(this, Progress);
        main_recycler_name.setAdapter(ProgressAdapter);

        GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
        main_recycler_view.setLayoutManager(layoutManager);
        Honor();
        adapter=new ClassAdapter(MainActivity.this,honor);
        main_recycler_view.setAdapter(adapter);
        StudentStudy();
        StudentProgress();
        arrayAdapter= new ArrayAdapter(this, android.R.layout.simple_list_item_1, initialList);
        lv_debug.setAdapter(arrayAdapter);
    }

    private void initList() {
        mNormalBanner = (MZBannerView) findViewById(R.id.banner_normal);
        mNormalBanner.setIndicatorVisible(false);
        List<String> strings = mainModel.ClassBanner();
        if (strings.size()!=0) {
            AppUtlis.setpa(mNormalBanner, strings);
        }
    }
    @Override
    public void onPause() {
        super.onPause();
        mNormalBanner.pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mNormalBanner.start();
    }
    private AlertDialog dialog;
    private EditText et_name;
    private EditText et_pwd;
    private Button bt_login;
    private void showLoginDialog(final int i) throws PackageManager.NameNotFoundException {
        LayoutInflater inflater = getLayoutInflater();
        final View view = inflater
                .inflate(R.layout.dialog_login, null);
        et_name= (EditText) view.findViewById(R.id.et_name);
        et_pwd= (EditText) view.findViewById(R.id.et_pwd);

        bt_login= (Button) view.findViewById(R.id.bt_login);
        bt_login.setOnClickListener(this);
        TextView tv_versionName= (TextView) view.findViewById(R.id.tv_versionName);
        tv_versionName.setText("当前版本："+AppUtlis.packageMas(MainActivity.this));
        dialog = new AlertDialog.Builder(MainActivity.this).create();
        dialog.setCancelable(false);
        AppUtlis.backgroundAlpha(MainActivity.this,0.06F);
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK
                            && event.getRepeatCount() == 0) {
                        if (i==1) {
                            finish();
                        }else if (i==0){
                            dialog.dismiss();
                        }
                        AppUtlis.backgroundAlpha(MainActivity.this,1);
                    }

                    return false; // 默认返回 false
                }
            });
        dialog.setView(view);
        dialog.show();
    }
    List<StudentNews> classNewses =new ArrayList<>();
    private boolean bl_debug=true;
    private void initIdNumber() {
        tbCard.requestFocus();
        tbCard.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                if (actionId== EditorInfo.IME_ACTION_SEND||actionId == EditorInfo.IME_ACTION_DONE||event != null && KeyEvent.KEYCODE_ENTER==event.getKeyCode()&&KeyEvent.ACTION_DOWN==event.getAction()){
                    String strCardNo=tbCard.getText().toString().trim();
                    Log.e("ATG",strCardNo);
                    setCard(strCardNo);
//                }
                return false;
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_calssname:
                try {
                    showLoginDialog(0);
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
                break;
            //登录
            case R.id.bt_login:
                String name=et_name.getText().toString().trim();
                String pwd=et_pwd.getText().toString().trim();

                //收起键盘
                InputMethodManager imm =  (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                if(imm != null) {
                    imm.hideSoftInputFromWindow(dialog.getWindow().getDecorView().getWindowToken(),
                            0);
                }
                if (name.equals("hjt2018")&&pwd.equals("123456")){
                    if (bl_debug) {
                        initialList.add(0,ClassCalendar.getStringtHour()+": 设备号:"+android.os.Build.SERIAL);
                        lv_debug.setVisibility(View.VISIBLE);
                        bl_debug=false;
                    }else{
                        lv_debug.setVisibility(View.GONE);
                        bl_debug=true;
                    }
                    dialog.dismiss();
                    AppUtlis.backgroundAlpha(MainActivity.this,1);
                    return;
                }
                mainModel.Login(name,pwd);
                break;
        }
    }

    /**
     * 广播类
     */
    private class NewsReceiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            switch (action){
                case Constant.NEWS:
                    getNews();
                    break;
                case Constant.WEATHER:
                    String weather=intent.getStringExtra(Constant.WEATHER);
                    tv_weather.setText(weather);
                    break;
                case Constant.TO:
                    getTo();
                    break;
                case Constant.LOGIN:
                    String type=intent.getStringExtra("type");
                    if(type.equals("1")){
                        String loginerr=intent.getStringExtra(Constant.LOGIN);
                        Toast.makeText(MainActivity.this,loginerr,Toast.LENGTH_LONG).show();
                    }else if(type.equals("2")){
                        dialog.dismiss();
                        AppUtlis.backgroundAlpha(MainActivity.this,1);
                        getTo();
                        tv_calssname.setText(mainModel.classname());
                        tv_headmaster.setText("班主任:"+mainModel.classteachername());
                        tv_SchoolTitle.setText(mainModel.ArtSchool());
                        ArtSchool();
                        tv_SchoolContent.startWithList(ArtSchool);
                        Scheduleafternoon();
                        Schedulemo();
                        Labour();
                        List<String> strings = mainModel.ClassBanner();
                        Log.e("ATG","图片地址"+strings);
                        if (strings.size()!=0) {
                            mNormalBanner.setVisibility(View.VISIBLE);
                            AppUtlis.setpa(mNormalBanner, strings);
                            mNormalBanner.notifyDataSetChanged();
                            mNormalBanner.start();
                        }else{
                            mNormalBanner.setVisibility(View.GONE);
                        }
                        Honor();
                        adapter.notifyDataSetChanged();
                        ArtClass();
                        text1_stv.startWithList(artCalss);
                        StudentStudy();
                        StudentProgress();
                        getNews();
                    }
                    break;
                case Constant.DELETE:
                    getNews();
                    break;
                case Constant.ERR:
                    int visibility = lv_debug.getVisibility();
                    if (visibility==0){
                        String err=intent.getStringExtra(Constant.ERR);
//                        initialList.
                        initialList.add(0,err);
                        arrayAdapter.notifyDataSetChanged();
                    }
                    break;
                case Constant.STUDYPROGRESS:
                    StudentStudy();
                    StudentProgress();
                    getTo();
                    break;
                case Constant.SCHEDULE:
                    Schedulemo();
                    Scheduleafternoon();
                    break;
                case Constant.BANNER:
                    List<String> strings = mainModel.ClassBanner();
                    if (strings.size()!=0) {
                        mNormalBanner.setVisibility(View.VISIBLE);
                        AppUtlis.setpa(mNormalBanner, strings);
                        mNormalBanner.notifyDataSetChanged();
                        mNormalBanner.start();
                    }else{
                        mNormalBanner.setVisibility(View.GONE);
                    }
                    break;
                case Constant.HONOR:
                    Honor();
                    adapter.notifyDataSetChanged();
                    break;
                case Constant.ARTCLASS:
                    ArtClass();
                    text1_stv.startWithList(artCalss);
                    break;
                case Constant.ARTSCHOOL:
                    tv_SchoolTitle.setText(mainModel.ArtSchool());
                    ArtSchool();
                    tv_SchoolContent.startWithList(ArtSchool);
                    break;
                case Constant.LABOUR:
                    Labour();
                    break;
                case Constant.NAME:
                    tv_calssname.setText(mainModel.classname());
                    tv_headmaster.setText("班主任:"+mainModel.classteachername());
                    break;
            }

        }
    }

    /**
     * @return IntentFilter 广播
     */
    private IntentFilter filter(){
        IntentFilter filter = new IntentFilter();
        filter.addAction(Constant.NEWS);//消息
        filter.addAction(Constant.WEATHER);//天气
        filter.addAction(Constant.TO);//人数
        filter.addAction(Constant.LOGIN);//登录
        filter.addAction(Constant.DELETE);//已成已读消息
        filter.addAction(Constant.ERR);//调试
        filter.addAction(Constant.STUDYPROGRESS);//学习进步之星
        filter.addAction(Constant.SCHEDULE);//课程班
        filter.addAction(Constant.BANNER);//轮播图
        filter.addAction(Constant.HONOR);//班级荣誉
        filter.addAction(Constant.ARTCLASS);//班级公告
        filter.addAction(Constant.ARTSCHOOL);//校园动态
        filter.addAction(Constant.LABOUR);//值日
        filter.addAction(Constant.NAME);
        return filter;
    }

    /**
     * 判断当前是否登录
     */
    public void getNamePwd(){
        if (mainModel.getIsnamepwd()){
            try {
                showLoginDialog(1);
                return;
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel( );
            timer = null;
        }
        unregisterReceiver(newsReceiver);
    }
    /**
     *人数
     */
    public void getTo(){
        tv_count.setText(mainModel.getNumber()+" 人，");
        tv_to.setText(mainModel.getTonum()+"");
        tv_noto.setText((mainModel.getNumber()-mainModel.getTonum())+"");
    }

    /**
     * 早上课程表
     */
    public void Schedulemo(){
        ll_schedule.removeAllViews();
        List<String> strings = mainModel.ClassScheduleMorning();
        String[] s={"一","二","三","四","五","六","七","八","九","十","一","二","三","四","五","六","七","八","九","十"};
        for (int i=0;i<strings.size();i++){
            String strs="第"+s[i]+"节 "+strings.get(i);
            TextView textView=new TextView(this);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            textView.setLayoutParams(layoutParams);
            layoutParams.setMargins(0,(int)AppUtlis.px2dp(this,5),0,0);
            textView.setText(strs);
            textView.setTextColor(Color.parseColor("#444444"));
            textView.setTextSize(AppUtlis.px2sp(this,18));
            ll_schedule.addView(textView);
            Log.e("ATG","课表"+strs);
        }
    }

    /**
     * 下午课程表
     */
    public void Scheduleafternoon(){
        ll_schedulea.removeAllViews();
        List<String> strings = mainModel.ClassScheduleaFternoon();
        String[] s={"一","二","三","四","五","六","七","八","九","十","一","二","三","四","五","六","七","八","九","十"};
        for (int i=0;i<strings.size();i++){
            String strs="第"+s[i]+"节 "+strings.get(i);
            TextView textView=new TextView(this);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            textView.setLayoutParams(layoutParams);
            layoutParams.setMargins(0,(int)AppUtlis.px2dp(this,5),0,0);
            textView.setText(strs);
            textView.setTextColor(Color.parseColor("#444444"));
            textView.setTextSize(AppUtlis.px2sp(this,18));
            ll_schedulea.addView(textView);
            Log.e("ATG","课表"+strs);
        }
    }

    /**
     * 值日
     */
    public void Labour(){
        String str = mainModel.ClassLabour();
        tv_labur.setText(str);
    }
    /**
     * 获取当前消息
     */
    public  void getNews(){
        BaseApplication.getDaoInstant().clear();
        String sign = mainModel.StudentSign();
        if (sign.equals("8")){
            ll_news.setVisibility(View.GONE);
        }else{
            ll_news.setVisibility(View.VISIBLE);
            tv_news.initView(sign,8000);
        }
    }

    /**
     * @param strCardNo 卡号
     *   打卡
     */
    public void setCard(String strCardNo){
        List<Cardnumber> card = CardDao.queryLove(strCardNo);
        for (int i=0;i<card.size();i++){
            if (card.get(i).getType()==0){
                if (bl_debug) {
                    initialList.add(0,ClassCalendar.getStringtHour()+": 设备号:"+android.os.Build.SERIAL);
                    lv_debug.setVisibility(View.VISIBLE);
                    bl_debug=false;
                }else{
                    lv_debug.setVisibility(View.GONE);
                    bl_debug=true;
                }
            }else if(card.get(i).getType()==1) {
                    StudentCard(card,i);
            }else if (card.get(i).getType()==2){
                    Intent intent=new Intent(MainActivity.this, StudentPhotosActivity.class);
                    intent.putExtra(Constant.WEATHER,tv_weather.getText());
                    startActivity(intent);
            }
        }
        initialList.add(0,ClassCalendar.getStringtHour()+":  卡号:"+strCardNo);
        arrayAdapter.notifyDataSetChanged();
        tbCard.setText("");
    }
    List<CardStudent> Study=new ArrayList<>();
    List<CardStudent> Progress=new ArrayList<>();

    /**
     * 学习之星
     */
    public void StudentStudy(){
        BaseApplication.getDaoInstant().clear();
        Study.clear();
        List<CardStudent> StudentStudy = CardDao.queryStudentHonor(0,1);
        if (StudentStudy.size()!=0&&StudentStudy.size()>3){
            for (int i=0;i<3;i++){
                if (StudentStudy.get(i).getHonor_id()==3){
                    Study.add(StudentStudy.get(i));
                }else if (StudentStudy.get(i).getHonor_id()==2) {
                    Study.add(StudentStudy.get(i));
                }
            }
        }else if(StudentStudy.size()!=0&&StudentStudy.size()<=3){
            for (CardStudent student:StudentStudy){
                if (student.getHonor_id()==3){
                    Study.add(student);
                }else if (student.getHonor_id()==2){
                    Study.add(student);
                }
            }
        }

        StudyAdapter.notifyDataSetChanged();
    }
    /**
     * 进步之星
     */
    public void StudentProgress(){
        BaseApplication.getDaoInstant().clear();
        Progress.clear();
        List<CardStudent> StudentStudy = CardDao.queryStudentHonor(0,2);
        if (StudentStudy.size()!=0&&StudentStudy.size()>3){
            for (int i=0;i<3;i++){
                if (StudentStudy.get(i).getHonor_id()==3){
                    Progress.add(StudentStudy.get(i));
                }else if (StudentStudy.get(i).getHonor_id()==1) {
                    Progress.add(StudentStudy.get(i));
                }
            }
        }else if(StudentStudy.size()!=0&&StudentStudy.size()<=3){

            for (CardStudent student:StudentStudy){
                if (student.getHonor_id()==3){
                    Progress.add(student);
                }else if (student.getHonor_id()==1){
                    Progress.add(student);
                }
            }
        }
        ProgressAdapter.notifyDataSetChanged();
    }

    /**
     * 班级荣誉
     */
    public void Honor(){
        honor.clear();
        List<String> list = mainModel.ClassHonor();
        for (String str:list){
            honor.add(str);
        }
    }
    List<String> artCalss=new ArrayList<>();
    List<String> ArtSchool=new ArrayList<>();
    /**
     * 班级公告
     */
    public void ArtClass(){
        artCalss.clear();
        List<String> Artcalss = mainModel.ArtCalss();
                for (String str:Artcalss) {
                    artCalss.add(str);
                }
    }
    /**
     * 校园动态
     */
    public void ArtSchool(){
        ArtSchool.clear();
        List<String> Artcalss = mainModel.ArtSchools();
        for (String str:Artcalss){
            ArtSchool.add(str);
        }
    }

    public void StudentCard(List<Cardnumber> card,int i){
        classNewses.clear();
        //当前是学生滴卡
        final CardStudent cardStudnet = card.get(i).getCardStudnet();
        //查看未读消息
        List<StudentNews> newses = cardStudnet.getNewses();
        if (newses.size() != 0) {
            for (StudentNews news : newses) {
                classNewses.add(news);
            }
            AppUtlis.ListSort(classNewses);
            mainModel.deleteNews(classNewses.get(0).getId(),cardStudnet.getId(), cardStudnet.getStudent_name(), classNewses.get(0).getNewsTime(), classNewses.get(0).getNewsContent());
            DialogUtlis.showNewsDialog(MainActivity.this,classNewses.get(0).getId(),cardStudnet.getStudent_name(),classNewses.get(0).getNewsTime(),classNewses.get(0).getNewsContent());
        } else {
            if (cardStudnet.getStudentSign() == null) {
                mainModel.Timecard(cardStudnet.getCard_no(), new AsyncTaskSoapUtil.Callback() {
                    @Override
                    public void onPost(String data) {
                        switch (data) {
                            case "":
                                initialList.add(0, ClassCalendar.getIntDay() + ":  考勤接口访问不上");
                                arrayAdapter.notifyDataSetChanged();
                                setSign(cardStudnet, 1);
                                break;
                            case "00":
                                setSign(cardStudnet, 0);
                                break;
                            default:
                                setSign(cardStudnet, 1);
                                break;
                        }
                    }
                });

            } else {
                mainModel.Timecard(cardStudnet.getCard_no(), new AsyncTaskSoapUtil.Callback() {
                    @Override
                    public void onPost(String data) {
                        Log.e("debug",data);
                        switch (data) {
                            case "":
                                initialList.add(0, ClassCalendar.getIntDay() + ":  考勤接口访问不上");
                                arrayAdapter.notifyDataSetChanged();
                                upSign(cardStudnet, 1);
                                break;
                            case "00":
                                upSign(cardStudnet, 0);
                                break;
                            default:
                                upSign(cardStudnet, 1);
                                break;
                        }
                    }
                });
            }
        }
        Log.e("ATG", cardStudnet.getStudent_name());
    }
    public void setSign(CardStudent cardStudent,int type){
        StudentSign sign = new StudentSign(cardStudent.getId(), ClassCalendar.getStringMinuts(),type,ClassCalendar.getCardtime(),cardStudent.getCard_no());
        CardDao.insertSign(sign);
        getTo();
        DialogUtlis.showStudentDialog(MainActivity.this,cardStudent,type);
    }
    public void upSign(CardStudent cardStudent,int type){
        StudentSign sign = new StudentSign(cardStudent.getId(), ClassCalendar.getStringMinuts(),type,ClassCalendar.getCardtime(),cardStudent.getCard_no());
        CardDao.updateSign(sign);
        getTo();
        DialogUtlis.showStudentDialog(MainActivity.this,cardStudent,type);
    }
    Runnable run2 = new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                View rootview = MainActivity.this.getWindow().getDecorView();
                View aaa = rootview.findFocus();
                Log.i("tag", aaa.toString());
            }
        }
    };

}